//
//  ByCellCommitOrderAddressHad.m
//  itboye_shop_ios
//
//  Created by pro on 17/2/9.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellCommitOrderAddressHad.h"

@implementation ByCellCommitOrderAddressHad
{
    UIImageView *_iconView;             // 地址图标
    UILabel     *_nameLabel;            // 姓名
    UILabel     *_mobileLabel;          // 手机
    UILabel     *_addressLabel;         // 地址
    UIImageView *_bottomImageView;      // 底部的彩条
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    _iconView = [[UIImageView alloc] init];
    _iconView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_iconView];
    
    // 姓名
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.font = FONT(15);
    _nameLabel.textColor = TEXT_COLOR;
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nameLabel];
    
    // 手机
    _mobileLabel = [[UILabel alloc] init];
    _mobileLabel.font = FONT(13);
    _mobileLabel.textColor = TEXT_COLOR;
    _mobileLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_mobileLabel];
    
    // 地址
    _addressLabel = [[UILabel alloc] init];
    _addressLabel.numberOfLines = 2;
    _addressLabel.font = FONT(14);
    _addressLabel.textColor = TEXT_COLOR;
    _addressLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_addressLabel];
    
    _bottomImageView = [[UIImageView alloc] init];
    _bottomImageView.image = [UIImage imageNamed:@"shopcar_dizhixian"];
    _bottomImageView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_bottomImageView];
    
}

- (void)setModel:(ByModelAddress *)model {
    
    _model = model;
    
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    CGFloat margin          = [UIScreen mainScreen].scale == 3 ? 20 : 15;
    
    // 设置位置
    _mobileLabel.frame      = CGRectMake(0, 20, 100, 20);
    _mobileLabel.right      = self.width - 40;
    
    _iconView.frame         = CGRectMake(margin, 0, 20, 20);
    _iconView.y             = self.height / 2;
    
    _nameLabel.frame        = CGRectMake(_iconView.right + 10, _mobileLabel.top, _mobileLabel.left - 10 - (_iconView.right + 10), _mobileLabel.height);
    
    _addressLabel.frame     = CGRectMake(_nameLabel.left, _nameLabel.bottom + 10, _mobileLabel.right - margin, 35);
    
    _bottomImageView.frame  = CGRectMake(0, 0, self.width, self.width * 10 / 700);
    _bottomImageView.bottom = self.height;
    
    // 设置属性
    _nameLabel.text         = [NSString stringWithFormat:@"收货人：%@", _model.contactname];
    _mobileLabel.text       = _model.mobile;
    _addressLabel.text      = [NSString stringWithFormat:@"收货地址：%@%@%@%@", _model.province, _model.city, _model.area, _model.detailinfo];
    
}

@end
